﻿<!-- 
   GSearchPad.xaml
   Declares the UI markup and data bindings for the GSearchPad
   application.
    
   Copyright (c) 2009, 2010, Mark Betz 
   
   All rights reserved. 
   Redistribution and use in source and binary forms, with or without 
   modification, are permitted provided that the following conditions are met: 
   
     * Redistributions of source code must retain the above copyright 
       notice, this list of conditions and the following disclaimer. 
     * Redistributions in binary form must reproduce the above copyright 
       notice, this list of conditions and the following disclaimer in the 
       documentation and/or other materials provided with the distribution. 
     * Neither the name of the Author nor the names of contributors may be 
       used to endorse or promote products derived from this software
       without specific prior written permission. 
       
   THIS SOFTWARE IS PROVIDED BY MARK BETZ ''AS IS'' AND ANY  EXPRESS OR
   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
   IN NO EVENT SHALL MARK BETZ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
   OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
-->
<Window x:Class="GSearchPad.MainWin"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:gconv="clr-namespace:HTMLConverter;assembly=GConvert"
    Title="Google Searchpad" Height="768" Width="1024"
    Background="DimGray">
    <Grid>
        <!-- The main grid splits the window in two, with a 200 pixel fixed-size
        navigation bar on the left, and the right portion scaling with the view -->
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        
        <!-- The left panel content contains the controls for setting search
        arguments. There is a root set of arguments, and then a lower panel
        that displays based on the type of search -->
        <Grid x:Name="LeftPanel"
            Background="DarkGray"
            Grid.Column="0">
            
            <!-- Styles for the controls in the argument panels -->
            <Grid.Resources>
                <Style x:Key="ArgLabel" TargetType="TextBlock">
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="Margin" Value="10,10,0,0" />
                    <Setter Property="Height" Value="20" />
                    <Setter Property="FontFamily" Value="Arial" />
                    <Setter Property="FontSize" Value="14" />
                    <Setter Property="Foreground" Value="Black" />
                </Style>
                <Style TargetType="TextBox">
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="Margin" Value="10,0,0,0" />
                    <Setter Property="Height" Value="20" />
                    <Setter Property="FontFamily" Value="Arial" />
                    <Setter Property="FontSize" Value="12" />
                    <Setter Property="Foreground" Value="Black" />
                </Style>
                <Style TargetType="ComboBox">
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="Margin" Value="10,0,0,0" />
                    <Setter Property="Height" Value="20" />
                    <Setter Property="FontFamily" Value="Arial" />
                    <Setter Property="FontSize" Value="12" />
                    <Setter Property="Foreground" Value="Black" />
                </Style>
                <Style TargetType="CheckBox">
                    <Setter Property="HorizontalAlignment" Value="Left" />
                    <Setter Property="Margin" Value="10,0,0,0" />
                    <Setter Property="Height" Value="20" />
                    <Setter Property="FontFamily" Value="Arial" />
                    <Setter Property="FontSize" Value="12" />
                    <Setter Property="Foreground" Value="Black" />
                </Style>
            </Grid.Resources>
            
            <!-- The top row is a spacer, the middle one holds the base argument controls,
            and the lower one holds the search-specific controls as needed -->
            <Grid.RowDefinitions>
                <RowDefinition Height="12" />
                <RowDefinition Height="170" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            
            <!-- The panel containing controls for the base arguments -->
            <StackPanel x:Name="BaseArgsPanel"
                Orientation="Vertical"
                Grid.Row="1">
                <TextBlock Text="Host language:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="HostLangList"
                    ItemsSource="{Binding Source={StaticResource HostLangs}}"
                    SelectedIndex="18"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="Result size:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="ResultSize"
                    ItemsSource="{Binding Source={StaticResource SearchResultSizes}}"
                    SelectedIndex="1"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="API Key (optional):" Style="{StaticResource ArgLabel}" />
                <TextBox x:Name="ApiKeyEdit" Width="150" />
            </StackPanel>
            
            <!-- Web search arguments panel -->
            <StackPanel x:Name="WebArgsPanel"
                Grid.Row="2"
                Visibility="Visible"
                Orientation="Vertical">
                <TextBlock Text="Safe Search:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="WebSafeSearch"
                    ItemsSource="{Binding Source={StaticResource SearchSafety}}"
                    SelectedIndex="2"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="Result language:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="ResLangList"
                    ItemsSource="{Binding Source={StaticResource ResultLangs}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="Filter duplicates:" Style="{StaticResource ArgLabel}" />
                    <CheckBox x:Name="RemoveDupes" IsChecked="True" Margin="10,11,0,0" />
                </StackPanel>
                <TextBlock Text="Search in country:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="CountryList"
                    ItemsSource="{Binding Source={StaticResource SearchCountries}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="Search Eng. ID (optional):" Style="{StaticResource ArgLabel}" />
                <TextBox x:Name="CSEIdEdit" Width="150" />
                <TextBlock Text="Search Eng. Url (optional):" Style="{StaticResource ArgLabel}" />
                <TextBox x:Name="CSEUrlEdit" Width="150" />
            </StackPanel>

            <!-- Image search arguments panel -->
            <StackPanel x:Name="ImageArgsPanel"
                Grid.Row="2"
                Visibility="Collapsed"
                Orientation="Vertical">
                <TextBlock Text="Search Domain:" Style="{StaticResource ArgLabel}" />
                <TextBox x:Name="ImageSearchDomainEdit" Width="150" />
                <TextBlock Text="Safe Search:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="ImageSearchSafetyList"
                    ItemsSource="{Binding Source={StaticResource SearchSafety}}"
                    SelectedIndex="2"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="Image Size:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="ImageSearchSizeList"
                    ItemsSource="{Binding Source={StaticResource SearchImageSizes}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="Image Colorization:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="ImageSearchColorizationList"
                    ItemsSource="{Binding Source={StaticResource SearchImageColorization}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="Image Color:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="ImageSearchColorList"
                    ItemsSource="{Binding Source={StaticResource SearchImageColor}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="Image Type:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="ImageSearchTypeList"
                    ItemsSource="{Binding Source={StaticResource SearchImageTypes}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="File Type:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="ImageSearchFileTypeList"
                    ItemsSource="{Binding Source={StaticResource SearchImageFileTypes}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
            </StackPanel>

            <!-- Video search arguments panel -->
            <StackPanel x:Name="VideoArgsPanel"
                Grid.Row="2"
                Visibility="Collapsed"
                Orientation="Vertical">
                <TextBlock Text="Video Scoring:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="VideoSearchScoringList"
                    ItemsSource="{Binding Source={StaticResource SearchScorings}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
            </StackPanel>

            <!-- Book search arguments panel -->
            <StackPanel x:Name="BookArgsPanel"
                Grid.Row="2"
                Visibility="Collapsed"
                Orientation="Vertical">
                <TextBlock Text="Book types:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="BookViewTypesList"
                    ItemsSource="{Binding Source={StaticResource SearchBookViewTypes}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
            </StackPanel>

            <!-- Local search arguments panel -->
            <StackPanel x:Name="LocalArgsPanel"
                Grid.Row="2"
                Visibility="Collapsed"
                Orientation="Vertical">
                <TextBlock Text="Search Center (lat,lng):" Style="{StaticResource ArgLabel}" />
                <StackPanel Orientation="Horizontal">
                    <TextBox x:Name="SCLatEdit" Width="75"   />
                    <TextBlock Text="," Style="{StaticResource ArgLabel}" 
                        FontSize="12" />
                    <TextBox x:Name="SCLngEdit" Width="75" />
                </StackPanel>
                <TextBlock Text="Bounding Box:" Style="{StaticResource ArgLabel}" />
                <StackPanel Orientation="Horizontal">
                    <TextBox x:Name="BB1Edit" Width="75" />
                    <TextBlock Text="," Style="{StaticResource ArgLabel}" 
                        FontSize="12" />
                    <TextBox x:Name="BB2Edit" Width="75" />
                </StackPanel>
                <TextBlock Text="Result Types:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="LocalResultTypesList"
                    ItemsSource="{Binding Source={StaticResource SearchLocalResults}}"
                    SelectedIndex="2"
                    IsEditable="False"
                    Width="120" />
            </StackPanel>

            <!-- Blog search arguments panel -->
            <StackPanel x:Name="BlogArgsPanel"
                Grid.Row="2"
                Visibility="Collapsed"
                Orientation="Vertical">
                <TextBlock Text="Blog Scoring:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="BlogSearchScoringList"
                    ItemsSource="{Binding Source={StaticResource SearchScorings}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
            </StackPanel>

            <!-- Patent search arguments panel -->
            <StackPanel x:Name="PatentArgsPanel"
                Grid.Row="2"
                Visibility="Collapsed"
                Orientation="Vertical">
                <TextBlock Text="Patent Scoring:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="PatentSearchScoringList"
                    ItemsSource="{Binding Source={StaticResource SearchScorings}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="Patent Types:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="PatentSearchStatusList"
                    ItemsSource="{Binding Source={StaticResource SearchPatentStatus}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
            </StackPanel>

            <!-- News search arguments panel -->
            <StackPanel x:Name="NewsArgsPanel"
                Grid.Row="2"
                Visibility="Collapsed"
                Orientation="Vertical">
                <TextBlock Text="News Scoring:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="NewsSearchScoringList"
                    ItemsSource="{Binding Source={StaticResource SearchScorings}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="Location (zip/city,state):" Style="{StaticResource ArgLabel}" />
                <TextBox x:Name="NewsSearchLocationEdit" 
                    Width="150" 
                    TextChanged="NewsSearchLocationEdit_TextChanged" />
                <TextBlock Text="Quoted Person ID:" Style="{StaticResource ArgLabel}" />
                <TextBox x:Name="NewsSearchQPIDEdit" 
                    Width="150" 
                    TextChanged="NewsSearchQPIDEdit_TextChanged" />
                <TextBlock Text="News Topics:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="NewsSearchTopicList"
                    ItemsSource="{Binding Source={StaticResource SearchNewsTopics}}"
                    SelectedIndex="0"
                    SelectionChanged="NewsSearchTopicList_SelectionChanged"
                    IsEditable="False"
                    Width="120" />
                <TextBlock Text="News Editions:" Style="{StaticResource ArgLabel}" />
                <ComboBox x:Name="NewsSearchEditionList"
                    ItemsSource="{Binding Source={StaticResource SearchNewsEditions}}"
                    SelectedIndex="0"
                    IsEditable="False"
                    Width="120" />
            </StackPanel>
        </Grid>
        
        <!-- The right panel of the main grid contains the search bar, tab control
        and the results -->
        <Grid x:Name="RightPanel"
            Background="Burlywood"
            Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="50" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            
            <!-- search edit and Go button -->
            <StackPanel Grid.Row="0" Orientation="Horizontal">
                <TextBlock Text="Search terms:"
                    Width="100"
                    Margin="12,15,0,0"
                    Height="20"
                    FontFamily="Arial"
                    FontSize="14"
                    Foreground="Brown" />
                <TextBox x:Name="SearchTermsEdit"
                    TextChanged="SearchTermsEdit_TextChanged"
                    Margin="0,10,0,0"
                    Width="450"
                    Height="25"
                    FontSize="14" 
                    Foreground="DimGray" />
                <Button x:Name="GoSearchButton"
                    IsEnabled="False"
                    Width="50"
                    Height="25"
                    Margin="10,10,0,0"
                    Content="Go" 
                    Click="GoSearchButton_OnClick" />
            </StackPanel>
            
            <!-- Results viewer panel -->
            <Grid x:Name="ResultsGrid" Grid.Row="1">
                <Grid.Resources>
                    <gconv:HtmlToFlowDocConverter x:Key="htmlToFlowDocConverter" />
                    <Style x:Key="TitleLink" TargetType="Hyperlink">
                        <Setter Property="FontSize" Value="14" />
                        <Setter Property="FontWeight" Value="bold" />
                        <Setter Property="Foreground" Value="Brown" />
                        <Setter Property="FontStyle" Value="Normal" />
                        <Setter Property="TextDecorations" Value="None" />
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Foreground" Value="Red" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                    <Style x:Key="SmallLink" TargetType="Hyperlink">
                        <Setter Property="FontSize" Value="12" />
                        <Setter Property="FontWeight" Value="normal" />
                        <Setter Property="Foreground" Value="Brown" />
                        <Setter Property="FontStyle" Value="Normal" />
                        <Setter Property="TextDecorations" Value="None" />
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="Foreground" Value="Red" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                    <Style x:Key="LabelStyle" TargetType="TextBlock">
                        <Setter Property="FontSize" Value="12" />
                    </Style>
                    <Style x:Key="ValueStyle" TargetType="TextBlock">
                        <Setter Property="FontSize" Value="12" />
                        <Setter Property="Foreground" Value="blue" />
                    </Style>
                    <Style TargetType="FlowDocument">
                        <Setter Property="FontFamily" Value="Arial" />
                        <Setter Property="FontSize" Value="12" />
                        <Setter Property="PagePadding" Value="0,5,0,0" />
                    </Style>
                    <Style TargetType="Label">
                        <Setter Property="FontFamily" Value="Arial" />
                        <Setter Property="FontSize" Value="14" />
                        <Setter Property="Foreground" Value="Blue" />
                        <Setter Property="Margin" Value="10,0,0,0" />
                    </Style>
                </Grid.Resources>                
                <TabControl x:Name="SearchTypeTabs"
                    SelectionChanged="SearchTypeTabs_SelectionChanged"
                    VerticalAlignment="Top"
                    Background="Transparent"
                    Height="{Binding ElementName=ResultsGrid, Path=ActualHeight}">
                    
                    <!-- Web results panel -->
                    <TabItem Header="Web">
                        <Grid x:Name="WebResultsPanel">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="40" />
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <TextBlock x:Name="WebResultsMsg"
                                    Margin="10,10,0,0"
                                    FontSize="14"
                                    Foreground="Brown" />
                            </Grid>
                            <ListBox Grid.Row="0" x:Name="WebResultsList"
                                Background="Transparent"
                                ItemsSource="{Binding}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="10,15,0,0" Orientation="Vertical">
                                            <TextBlock>
                                                <Hyperlink NavigateUri="{Binding Path=Url}"
                                                    Style="{StaticResource TitleLink}" 
                                                    RequestNavigate="HyperLink_RequestNavigate">
                                                    <TextBlock Text="{Binding Path=TitleNoFormatting}" />
                                                </Hyperlink>
                                            </TextBlock>
                                            <FlowDocumentScrollViewer 
                                                Document="{Binding Path=Content, Converter={StaticResource htmlToFlowDocConverter}}" 
                                                VerticalScrollBarVisibility="Hidden">
                                             </FlowDocumentScrollViewer>
                                            <TextBlock>
                                                <Hyperlink NavigateUri="{Binding Path=Url}"
                                                   Style="{StaticResource SmallLink}"
                                                   RequestNavigate="HyperLink_RequestNavigate">
                                                     <TextBlock Text="{Binding Path=VisibleUrl}" FontSize="12" />
                                                </Hyperlink>
                                            </TextBlock>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                            <Grid Grid.Row="1">
                                <StackPanel x:Name="WebResultsPager"
                                    Visibility="Collapsed" Orientation="Horizontal">
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </TabItem>

                    <!-- Image results panel -->
                    <TabItem Header="Images">
                        <Grid x:Name="ImageResultsPanel">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="40" />
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <TextBlock x:Name="ImageResultsMsg"
                                    Margin="10,10,0,0"
                                    FontSize="14"
                                    Foreground="Brown" />
                            </Grid>
                            <ListBox Grid.Row="0" x:Name="ImageResultsList"
                                Background="Transparent"
                                ItemsSource="{Binding}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="10,10,0,0" Orientation="Horizontal">
                                            <TextBlock>
                                                <Hyperlink NavigateUri="{Binding Path=UnescapedUrl}" 
                                                    TextDecorations="None"
                                                    RequestNavigate="HyperLink_RequestNavigate">
                                                    <Border BorderBrush="DimGray" 
                                                        BorderThickness="2" 
                                                        CornerRadius="10"
                                                        Background="DarkGray" 
                                                        Width="210" 
                                                        Height="160">
                                                        <Image Width="200" Height="150" 
                                                            Stretch="None" 
                                                            Source="{Binding Path=TbUrl}" />
                                                    </Border>
                                                </Hyperlink>
                                            </TextBlock>
                                            <StackPanel Margin="10,0,0,0" Orientation="Vertical">
                                                <TextBlock>
                                                    <Hyperlink NavigateUri="{Binding Path=UnescapedUrl}"
                                                        RequestNavigate="HyperLink_RequestNavigate"
                                                        Style="{StaticResource TitleLink}">
                                                        <TextBlock Text="{Binding Path=TitleNoFormatting}" />
                                                    </Hyperlink>
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <Hyperlink NavigateUri="{Binding Path=Url}"
                                                        Style="{StaticResource SmallLink}"
                                                        RequestNavigate="HyperLink_RequestNavigate">
                                                        <TextBlock Text="{Binding Path=VisibleUrl}" FontSize="12" />
                                                    </Hyperlink>
                                                    <Hyperlink NavigateUri="{Binding Path=OriginalContextUrl}"
                                                        Style="{StaticResource SmallLink}"
                                                        RequestNavigate="HyperLink_RequestNavigate">
                                                        <TextBlock Text="(Original Context)" FontSize="12"
                                                            Margin="5,0,0,0" />
                                                    </Hyperlink>
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <TextBlock Style="{StaticResource LabelStyle}" Text="{Binding Path=Width}" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" Text="x" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" Text="{Binding Path=Height}" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" Text="Pixels" />
                                                </TextBlock>
                                                <FlowDocumentScrollViewer 
                                                    Document="{Binding Path=Content, Converter={StaticResource htmlToFlowDocConverter}}" 
                                                    VerticalScrollBarVisibility="Hidden" />
                                            </StackPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                            <Grid Grid.Row="1">
                                <StackPanel x:Name="ImageResultsPager"
                                    Visibility="Collapsed" Orientation="Horizontal">
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </TabItem>

                    <!-- Video results panel -->
                    <TabItem Header="Video">
                        <Grid x:Name="VideoResultsPanel">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="40" />
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <TextBlock x:Name="VideoResultsMsg"
                                    Margin="10,10,0,0"
                                    FontSize="14"
                                    Foreground="Brown" />
                            </Grid>
                            <ListBox Grid.Row="0" x:Name="VideoResultsList"
                                Background="Transparent"
                                ItemsSource="{Binding}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="10,10,0,0" Orientation="Horizontal">
                                            <TextBlock>
                                                <Hyperlink NavigateUri="{Binding Path=PlayUrl}" 
                                                    TextDecorations="None"
                                                    RequestNavigate="HyperLink_RequestNavigate">
                                                    <Border BorderBrush="DimGray" 
                                                        BorderThickness="2" 
                                                        CornerRadius="10"
                                                        Background="DarkGray" 
                                                        Width="210" 
                                                        Height="160">
                                                        <Image Width="200" Height="150" 
                                                            Stretch="None" 
                                                            Source="{Binding Path=TbUrl}" />
                                                    </Border>
                                                </Hyperlink>
                                            </TextBlock>
                                            <StackPanel Margin="10,0,0,0" Orientation="Vertical">
                                                <TextBlock>
                                                    <Hyperlink NavigateUri="{Binding Path=PlayUrl}"
                                                        RequestNavigate="HyperLink_RequestNavigate"
                                                        Style="{StaticResource TitleLink}">
                                                        <TextBlock Text="{Binding Path=TitleNoFormatting}" />
                                                    </Hyperlink>
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <Hyperlink NavigateUri="{Binding Path=Url}"
                                                        Style="{StaticResource SmallLink}"
                                                        RequestNavigate="HyperLink_RequestNavigate">
                                                        <TextBlock Text="View in Original Context" FontSize="12" />
                                                    </Hyperlink>
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="Published:" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="{Binding Path=Published}" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="by" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="{Binding Path=Publisher}" />
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="Length: " />
                                                    <TextBlock Style="{StaticResource ValueStyle}" 
                                                        Text="{Binding Path=Duration}" />
                                                    <TextBlock Style="{StaticResource ValueStyle}" 
                                                        Text="seconds" />
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="Author: " />
                                                    <TextBlock Style="{StaticResource ValueStyle}" 
                                                        Text="{Binding Path=Author}" />
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="Rating: " />
                                                    <TextBlock Style="{StaticResource ValueStyle}" 
                                                        Text="{Binding Path=Rating}" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text=" Views: " />
                                                    <TextBlock Style="{StaticResource ValueStyle}" 
                                                        Text="{Binding Path=ViewCount}" />
                                                </TextBlock>
                                                <FlowDocumentScrollViewer 
                                                    Document="{Binding Path=Content, Converter={StaticResource htmlToFlowDocConverter}}" 
                                                    VerticalScrollBarVisibility="Hidden" />
                                            </StackPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                            <Grid Grid.Row="1">
                                <StackPanel x:Name="VideoResultsPager"
                                    Visibility="Collapsed" Orientation="Horizontal">
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </TabItem>

                    <!-- Books results panel -->
                    <TabItem Header="Books">
                        <Grid x:Name="BookResultsPanel">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="40" />
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <TextBlock x:Name="BookResultsMsg"
                                    Margin="10,10,0,0"
                                    FontSize="14"
                                    Foreground="Brown" />
                            </Grid>
                            <ListBox Grid.Row="0" x:Name="BookResultsList"
                                Background="Transparent"
                                ItemsSource="{Binding}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="10,10,0,0" Orientation="Horizontal">
                                            <TextBlock>
                                                <Hyperlink NavigateUri="{Binding Path=UnescapedUrl}" 
                                                    TextDecorations="None"
                                                    RequestNavigate="HyperLink_RequestNavigate">
                                                    <Border BorderBrush="DimGray" 
                                                        BorderThickness="2" 
                                                        CornerRadius="10"
                                                        Background="DarkGray" 
                                                        Width="160" 
                                                        Height="160">
                                                        <Image Width="150" Height="150" 
                                                            Stretch="Uniform" 
                                                            Source="{Binding Path=TbUrl}" />
                                                    </Border>
                                                </Hyperlink>
                                            </TextBlock>
                                            <StackPanel Margin="10,0,0,0" Orientation="Vertical">
                                                <TextBlock>
                                                    <Hyperlink NavigateUri="{Binding Path=UnescapedUrl}"
                                                        Style="{StaticResource TitleLink}" 
                                                        RequestNavigate="HyperLink_RequestNavigate">
                                                        <TextBlock Text="{Binding Path=TitleNoFormatting}" />
                                                    </Hyperlink>
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <FlowDocumentScrollViewer 
                                                        Document="{Binding Path=Authors, Converter={StaticResource htmlToFlowDocConverter}}" 
                                                        VerticalScrollBarVisibility="Hidden" />
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="{Binding Path=PublishedYear}" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text=", " />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="{Binding Path=PageCount}" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="pages" />
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="ISBN/ID: " />
                                                    <TextBlock Style="{StaticResource ValueStyle}" 
                                                        Text="{Binding Path=BookId}" />
                                                </TextBlock>
                                            </StackPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                            <Grid Grid.Row="1">
                                <StackPanel x:Name="BookResultsPager"
                                    Visibility="Collapsed" Orientation="Horizontal">
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </TabItem>

                    <!-- Local results panel -->
                    <TabItem Header="Local">
                        <Grid x:Name="LocalResultsPanel">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="40" />
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <TextBlock x:Name="LocalResultsMsg"
                                    Margin="10,10,0,0"
                                    FontSize="14"
                                    Foreground="Brown" />
                            </Grid>
                            <ListBox Grid.Row="0" x:Name="LocalResultsList"
                                Background="Transparent"
                                ItemsSource="{Binding}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="10,10,0,0" Orientation="Horizontal">
                                            <TextBlock>
                                                <Hyperlink NavigateUri="{Binding Path=Url}" 
                                                    TextDecorations="None"
                                                    RequestNavigate="HyperLink_RequestNavigate">
                                                    <Border BorderBrush="DimGray" 
                                                        BorderThickness="2" 
                                                        CornerRadius="10"
                                                        Background="DarkGray" 
                                                        Width="160" 
                                                        Height="110">
                                                        <Image Width="150" Height="100" 
                                                            Stretch="None" 
                                                            Source="{Binding Path=StaticMapUrl}" />
                                                    </Border>
                                                </Hyperlink>
                                            </TextBlock>
                                            <StackPanel Margin="10,0,0,0" Orientation="Vertical">
                                                <TextBlock>
                                                    <Hyperlink NavigateUri="{Binding Path=Url}"
                                                        Style="{StaticResource TitleLink}" 
                                                        RequestNavigate="HyperLink_RequestNavigate">
                                                        <TextBlock Text="{Binding Path=TitleNoFormatting}" />
                                                    </Hyperlink>
                                                </TextBlock>
                                                <TextBlock Style="{StaticResource LabelStyle}" Margin="0,5,0,0" 
                                                    Text="{Binding Path=StreetAddress}" />
                                                <StackPanel Margin="0,5,0,0" Orientation="Horizontal">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="{Binding Path=City}" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text=", " />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="{Binding Path=Region}" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text=", " />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="{Binding Path=Country}" />
                                                </StackPanel>
                                                <ListBox Background="Transparent"
                                                    BorderThickness="0"
                                                    ItemsSource="{Binding Path=PhoneNumbers}">
                                                    <ListBox.ItemsPanel>
                                                        <ItemsPanelTemplate>
                                                            <StackPanel Margin="0,5,0,0" Orientation="Horizontal" />
                                                        </ItemsPanelTemplate>
                                                    </ListBox.ItemsPanel>
                                                    <ListBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <TextBlock Style="{StaticResource LabelStyle}" 
                                                                Text="{Binding Path=Number}" />
                                                        </DataTemplate>
                                                    </ListBox.ItemTemplate>    
                                                </ListBox>
                                                <FlowDocumentScrollViewer 
                                                    Document="{Binding Path=Content, Converter={StaticResource htmlToFlowDocConverter}}" 
                                                    VerticalScrollBarVisibility="Hidden">
                                                </FlowDocumentScrollViewer>
                                            </StackPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                            <Grid Grid.Row="1">
                                <StackPanel x:Name="LocalResultsPager"
                                    Visibility="Collapsed" Orientation="Horizontal">
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </TabItem>

                    <!-- Blog results panel -->
                    <TabItem Header="Blog">
                        <Grid x:Name="BlogResultsPanel">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="40" />
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <TextBlock x:Name="BlogResultsMsg"
                                    Margin="10,10,0,0"
                                    FontSize="14"
                                    Foreground="Brown" />
                            </Grid>
                            <ListBox Grid.Row="0" x:Name="BlogResultsList"
                                Background="Transparent"
                                ItemsSource="{Binding}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="10,15,0,0" Orientation="Vertical">
                                            <TextBlock>
                                                <Hyperlink NavigateUri="{Binding Path=PostUrl}"
                                                    Style="{StaticResource TitleLink}" 
                                                    RequestNavigate="HyperLink_RequestNavigate">
                                                    <TextBlock Text="{Binding Path=TitleNoFormatting}" />
                                                </Hyperlink>
                                            </TextBlock>
                                            <StackPanel Margin="0,5,0,0" Orientation="Horizontal">
                                                <TextBlock Style="{StaticResource LabelStyle}" 
                                                    Text="By " />
                                                <TextBlock Style="{StaticResource LabelStyle}" 
                                                    Text="{Binding Path=Author}" />
                                                <TextBlock Style="{StaticResource LabelStyle}" 
                                                    Text=", " />
                                                <TextBlock Style="{StaticResource LabelStyle}" 
                                                    Text="{Binding Path=PublishedDate}" />
                                            </StackPanel>
                                            <StackPanel Margin="0,5,0,5" Orientation="Horizontal">
                                                <TextBlock Style="{StaticResource LabelStyle}" 
                                                    Text="Writing at " />
                                                <TextBlock>
                                                <Hyperlink NavigateUri="{Binding Path=BlogUrl}"
                                                    Style="{StaticResource SmallLink}"
                                                   RequestNavigate="HyperLink_RequestNavigate">
                                                     <TextBlock Text="{Binding Path=BlogUrl}" FontSize="12" />
                                                </Hyperlink>
                                            </TextBlock>
                                            </StackPanel>
                                            <FlowDocumentScrollViewer 
                                                Document="{Binding Path=Content, Converter={StaticResource htmlToFlowDocConverter}}" 
                                                VerticalScrollBarVisibility="Hidden">
                                            </FlowDocumentScrollViewer>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                            <Grid Grid.Row="1">
                                <StackPanel x:Name="BlogResultsPager"
                                    Visibility="Collapsed" Orientation="Horizontal">
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </TabItem>

                    <!-- Patent results panel -->
                    <TabItem Header="Patent">
                        <Grid x:Name="PatentResultsPanel">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="40" />
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <TextBlock x:Name="PatentResultsMsg"
                                    Margin="10,10,0,0"
                                    FontSize="14"
                                    Foreground="Brown" />
                            </Grid>
                            <ListBox Grid.Row="0" x:Name="PatentResultsList"
                                Background="Transparent"
                                ItemsSource="{Binding}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="10,10,0,0" Orientation="Horizontal">
                                            <TextBlock>
                                                <Hyperlink NavigateUri="{Binding Path=UnescapedUrl}" 
                                                    TextDecorations="None"
                                                    RequestNavigate="HyperLink_RequestNavigate">
                                                    <Border BorderBrush="DimGray" 
                                                        BorderThickness="2" 
                                                        CornerRadius="10"
                                                        Background="DarkGray" 
                                                        Width="210" 
                                                        Height="160">
                                                        <Image Width="200" Height="150" 
                                                            Stretch="Uniform" 
                                                            Source="{Binding Path=TbUrl}" />
                                                    </Border>
                                                </Hyperlink>
                                            </TextBlock>
                                            <StackPanel Margin="10,0,0,0" Orientation="Vertical">
                                                <TextBlock>
                                                    <Hyperlink NavigateUri="{Binding Path=UnescapedUrl}"
                                                        Style="{StaticResource TitleLink}" 
                                                        RequestNavigate="HyperLink_RequestNavigate">
                                                        <TextBlock Text="{Binding Path=TitleNoFormatting}" />
                                                    </Hyperlink>
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="Assignee: " />
                                                    <TextBlock Style="{StaticResource ValueStyle}" 
                                                        Text="{Binding Path=Assignee}" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text=" Application Date: " />
                                                    <TextBlock Style="{StaticResource ValueStyle}" 
                                                        Text="{Binding Path=ApplicationDate}" />
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="Number: " />
                                                    <TextBlock Style="{StaticResource ValueStyle}" 
                                                        Text="{Binding Path=PatentNumber}" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text=" Status: " />
                                                    <TextBlock Style="{StaticResource ValueStyle}" 
                                                        Text="{Binding Path=PatentStatus}" />
                                                </TextBlock>
                                                <FlowDocumentScrollViewer 
                                                    Document="{Binding Path=Content, Converter={StaticResource htmlToFlowDocConverter}}" 
                                                    VerticalScrollBarVisibility="Hidden" />
                                            </StackPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                            <Grid Grid.Row="1">
                                <Grid.Resources>
                                </Grid.Resources>
                                <StackPanel x:Name="PatentResultsPager"
                                    Visibility="Collapsed" Orientation="Horizontal">
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </TabItem>
                    
                    <!-- News results panel -->
                    <TabItem Header="News">
                        <Grid x:Name="NewsResultsPanel">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="40" />
                            </Grid.RowDefinitions>
                            <Grid Grid.Row="0">
                                <TextBlock x:Name="NewsResultsMsg"
                                    Margin="10,10,0,0"
                                    FontSize="14"
                                    Foreground="Brown" />
                            </Grid>
                            <ListBox Grid.Row="0" x:Name="NewsResultsList"
                                Background="Transparent"
                                ItemsSource="{Binding}">
                                <ListBox.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Margin="10,10,0,0" Orientation="Horizontal">
                                            <TextBlock>
                                                <Hyperlink NavigateUri="{Binding Path=UnescapedUrl}" 
                                                    TextDecorations="None"
                                                    RequestNavigate="HyperLink_RequestNavigate">
                                                    <Border BorderBrush="DimGray" 
                                                        BorderThickness="2" 
                                                        CornerRadius="10"
                                                        Background="DarkGray" 
                                                        Width="210" 
                                                        Height="160">
                                                        <Image Width="200" Height="150" 
                                                            Stretch="Uniform" 
                                                            Source="{Binding Path=Image.TbUrl}" />
                                                    </Border>
                                                </Hyperlink>
                                            </TextBlock>
                                            <StackPanel Margin="10,0,0,0" Orientation="Vertical">
                                                <TextBlock>
                                                    <Hyperlink NavigateUri="{Binding Path=UnescapedUrl}"
                                                        Style="{StaticResource TitleLink}" 
                                                        RequestNavigate="HyperLink_RequestNavigate">
                                                        <TextBlock Text="{Binding Path=TitleNoFormatting}" />
                                                    </Hyperlink>
                                                </TextBlock>
                                                <TextBlock Margin="0,5,0,0">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="{Binding Path=Publisher}" 
                                                        FontWeight="bold" />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text=", " />
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="{Binding Path=Location}" />
                                                </TextBlock>
                                                <TextBlock Style="{StaticResource LabelStyle}" 
                                                    Text="{Binding Path=PublishedDate}" />
                                                <FlowDocumentScrollViewer 
                                                    Document="{Binding Path=Content, Converter={StaticResource htmlToFlowDocConverter}}" 
                                                    VerticalScrollBarVisibility="Hidden" />
                                                <StackPanel Margin="0,10,0,0" Orientation="Vertical">
                                                    <TextBlock Style="{StaticResource LabelStyle}" 
                                                        Text="Related: " />
                                                    <ListBox Background="Transparent"
                                                        Margin="0,5,0,0"
                                                        BorderThickness="0"
                                                        ItemsSource="{Binding Path=RelatedStories}">
                                                        <ListBox.ItemsPanel>
                                                            <ItemsPanelTemplate>
                                                                <StackPanel Orientation="Horizontal" />
                                                            </ItemsPanelTemplate>
                                                        </ListBox.ItemsPanel>
                                                        <ListBox.ItemTemplate>
                                                            <DataTemplate>
                                                                <TextBlock>
                                                                    <Hyperlink NavigateUri="{Binding Path=UnescapedUrl}"
                                                                        RequestNavigate="HyperLink_RequestNavigate" 
                                                                        Style="{StaticResource SmallLink}">
                                                                        <TextBlock Text="{Binding Path=Publisher}" />
                                                                    </Hyperlink>
                                                                </TextBlock>
                                                            </DataTemplate>
                                                        </ListBox.ItemTemplate>
                                                    </ListBox>
                                                </StackPanel>
                                            </StackPanel>
                                        </StackPanel>
                                    </DataTemplate>
                                </ListBox.ItemTemplate>
                            </ListBox>
                            <Grid Grid.Row="1">
                                <StackPanel x:Name="NewsResultsPager"
                                    Visibility="Collapsed" Orientation="Horizontal">
                                </StackPanel>
                            </Grid>
                        </Grid>
                    </TabItem>
                </TabControl>
            </Grid>
        </Grid>
    </Grid>
</Window>
